package com.infore.airsupervise.ui.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.bigkoo.pickerview.TimePickerView;
import com.infore.airsupervise.R;
import com.infore.airsupervise.adapter.PointAnalyzeTableAdapter;
import com.infore.airsupervise.utils.DateUtil;
import com.inqbarna.tablefixheaders.TableFixHeaders;

import java.util.Calendar;
import java.util.Date;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 离线统计界面
 * Created by xiaotao on 2017/8/11.
 */

public class OfflineStatisticActivity extends BaseTitleBarActivity {

    @BindView(R.id.tv_startTime)
    TextView tvStartTime;
    @BindView(R.id.tv_endTime)
    TextView tvEndTime;
    @BindView(R.id.scroll_table)
    TableFixHeaders scrollTable;

    //时间
    private TimePickerView timePickerView = null;
    private TextView tvTitle= null;
    private String startTime;
    private String endTime;

    //表格
    private PointAnalyzeTableAdapter tableAdapter = null;
    private String[] topTitle;
    private String[] leftTitle;
    private String[][] tatbleData;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_statistic_offline);
        ButterKnife.bind(this);
        initView();
    }

    private void initView() {
        //titleBar
        title.setText("离线统计");
        rightMenu.setVisibility(View.INVISIBLE);
        //时间
        startTime = DateUtil.getStringByOffset(Calendar.getInstance().getTime(),DateUtil.FORMAT_DATE_HOUR,Calendar.HOUR_OF_DAY,-1);
        endTime = DateUtil.getCurrentDateStr(DateUtil.FORMAT_DATE_HOUR);
        tvStartTime.setText(startTime);
        tvEndTime.setText(endTime);
        //表格
        topTitle = new String[]{"离线次数","最长离线时长（分）","合计离线时长（分）"};
        leftTitle = new String[]{"实验站点1","实验站点2","实验站点3","实验站点4"};
        tatbleData = new String[][]{{"2","24442","322113"},{"0","0","0"},{"3","231322","333444"},{"1","1212","1212"}};

        tableAdapter = new PointAnalyzeTableAdapter(ctx,topTitle,leftTitle,tatbleData);
        scrollTable.setAdapter(tableAdapter);
    }
        /**
         * 初始化时间选择器
         */
        private void initTimePicker(){
            Calendar endSelectedDate = Calendar.getInstance();
            timePickerView = new TimePickerView.Builder(ctx, timeSelectListener)
                    .setTitleText("")
                    .setLabel("年", "月", "日", "点", "分", "秒")
                    .setType(new boolean[]{true,true,true,false,false,false})
                    .isCenterLabel(false)
                    .setDividerColor(Color.DKGRAY)
                    .setContentSize(18)
                    .setRangDate(null, endSelectedDate)
                    .setDate(endSelectedDate)
                    .setDecorView(null)
                    .build();
            tvTitle = (TextView) timePickerView.findViewById(com.bigkoo.pickerview.R.id.tvTitle);
        }


    private TimePickerView.OnTimeSelectListener timeSelectListener = new TimePickerView.OnTimeSelectListener() {
        @Override
        public void onTimeSelect(Date date, View v) {

        }
    };

    @OnClick({R.id.tv_startTime, R.id.tv_endTime})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_startTime:
            case R.id.tv_endTime:
                if(timePickerView ==null){
                    initTimePicker();
                }
                timePickerView.show(view);
                break;
        }
    }
}
